-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cstyle: add basic understanding of top-level macro invocations #16840
Closed
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
We quite often invoke macros outside of functions, usually to generate functions or data. cstyle inteprets these as function headers, which at least have opinions for indenting. This introduces a separate state for top-level macro invocations, and excludes it from matching functions. For the moment, most of the existing rules will continue to apply, but this gives us a way to add or removes rules targeting macros specifically. Sponsored-by: https://despairlabs.com/sponsor/ Signed-off-by: Rob Norris <[email protected]>
It's not uncommon to have empty parameters in code generator macros, usually when multiple parameters are concatenated or stringified into a single token or literal. So, exclude the space-before-comma check, which will allow construction like `MACRO_CALL(foo, , baz)`. Sponsored-by: https://despairlabs.com/sponsor/ Signed-off-by: Rob Norris <[email protected]>
In code generation macros, we often use names like `uint` when constructing handler functions. These are not being used as types, so exclude them from the admonishment to use POSIX type names. Sponsored-by: https://despairlabs.com/sponsor/ Signed-off-by: Rob Norris <[email protected]>
cstyle can handle these cases now, so we don't need to disable it. Sponsored-by: https://despairlabs.com/sponsor/ Signed-off-by: Rob Norris <[email protected]>
behlendorf
approved these changes
Dec 6, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice! This is a great bit of cleanup.
behlendorf
added
Status: Accepted
Ready to integrate (reviewed, tested)
and removed
Status: Code Review Needed
Ready for review and testing
labels
Dec 6, 2024
behlendorf
pushed a commit
that referenced
this pull request
Dec 6, 2024
It's not uncommon to have empty parameters in code generator macros, usually when multiple parameters are concatenated or stringified into a single token or literal. So, exclude the space-before-comma check, which will allow construction like `MACRO_CALL(foo, , baz)`. Sponsored-by: https://despairlabs.com/sponsor/ Reviewed-by: Brian Behlendorf <[email protected]> Signed-off-by: Rob Norris <[email protected]> Closes #16840
behlendorf
pushed a commit
that referenced
this pull request
Dec 6, 2024
In code generation macros, we often use names like `uint` when constructing handler functions. These are not being used as types, so exclude them from the admonishment to use POSIX type names. Sponsored-by: https://despairlabs.com/sponsor/ Reviewed-by: Brian Behlendorf <[email protected]> Signed-off-by: Rob Norris <[email protected]> Closes #16840
behlendorf
pushed a commit
that referenced
this pull request
Dec 6, 2024
cstyle can handle these cases now, so we don't need to disable it. Sponsored-by: https://despairlabs.com/sponsor/ Reviewed-by: Brian Behlendorf <[email protected]> Signed-off-by: Rob Norris <[email protected]> Closes #16840
behlendorf
pushed a commit
to behlendorf/zfs
that referenced
this pull request
Dec 6, 2024
We quite often invoke macros outside of functions, usually to generate functions or data. cstyle inteprets these as function headers, which at least have opinions for indenting. This introduces a separate state for top-level macro invocations, and excludes it from matching functions. For the moment, most of the existing rules will continue to apply, but this gives us a way to add or removes rules targeting macros specifically. Sponsored-by: https://despairlabs.com/sponsor/ Reviewed-by: Brian Behlendorf <[email protected]> Signed-off-by: Rob Norris <[email protected]> Closes openzfs#16840
behlendorf
pushed a commit
to behlendorf/zfs
that referenced
this pull request
Dec 6, 2024
It's not uncommon to have empty parameters in code generator macros, usually when multiple parameters are concatenated or stringified into a single token or literal. So, exclude the space-before-comma check, which will allow construction like `MACRO_CALL(foo, , baz)`. Sponsored-by: https://despairlabs.com/sponsor/ Reviewed-by: Brian Behlendorf <[email protected]> Signed-off-by: Rob Norris <[email protected]> Closes openzfs#16840
behlendorf
pushed a commit
to behlendorf/zfs
that referenced
this pull request
Dec 6, 2024
In code generation macros, we often use names like `uint` when constructing handler functions. These are not being used as types, so exclude them from the admonishment to use POSIX type names. Sponsored-by: https://despairlabs.com/sponsor/ Reviewed-by: Brian Behlendorf <[email protected]> Signed-off-by: Rob Norris <[email protected]> Closes openzfs#16840
behlendorf
pushed a commit
to behlendorf/zfs
that referenced
this pull request
Dec 6, 2024
cstyle can handle these cases now, so we don't need to disable it. Sponsored-by: https://despairlabs.com/sponsor/ Reviewed-by: Brian Behlendorf <[email protected]> Signed-off-by: Rob Norris <[email protected]> Closes openzfs#16840
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation and Context
I'm doing a major uplift of tunable macros (coming soon!), and got very tired of having to turn cstyle off all the time because it really has no idea what a macro is.
Description
Gives cstyle a modest understanding of top-level macro invocations:
uint
)Then, remove a ton of
/* CSTYLED */
and/* BEGIN CSTYLED */
escapes that aren't needed anymore.I've tried to remain very conservative for now, because I don't want to accidentally stop checking something in non-macro parts of the code (ie most of it).
How Has This Been Tested?
Tested during development, by removing some
CSTYLED
escapes, runningmake cstyle
, then adjusting the code until those go away.Types of changes
Checklist:
Signed-off-by
.